package com.voltmao.energy.Util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	public static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss";
	public static final String SHORT_PATTERN = "yyyy-MM-dd";
	public static final String MOUDLE_PATTERN = "yyyy-MM-dd HH:mm";
	public static final String MONTH_PATTERN = "yyyy-MM";
	public static final String HOUR_MINUTE_PATTERN = "HH:mm";
	public static final String DEFAULT_TIME_PATTERN = "HH:mm:ss";
	
	/**
	 * 
	 * @param date Date类型
	 * @param pattern 日期转换类型
	 * @return 日期字符串
	 */
	public static String formatDate(Date date, String pattern){
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(date);
	}
	
	/**
	 * 
	 * @param dateStr 日期字符串
	 * @param pattern 对应日期类型
	 * @return	Date日期
	 */
	public static Date parseDate(String dateStr, String pattern) {
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		try {
			return sdf.parse(dateStr);
		} catch (ParseException arg3) {
			arg3.printStackTrace();
			return null;
		}
	}

}
